home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / Lines < prev    next >
Text File  |  1995-06-12  |  4KB  |  165 lines

  1. %BEGIN Lines
  2.  
  3. % Copyright (C) 1993 David John Burrowes
  4. % Distributed under terms of GNU General Public License.
  5. % See COPYING.text in Convert PICT's CommentedPSCode for a copy
  6.  
  7. %%%%%%%%%%%%%
  8. %    Define the current pict point used for drawing lines
  9. %%%%%%%%%%%%%
  10. /currentX 0 def
  11. /currentY 0 def
  12.  
  13. %%%%%%%%%%%%%
  14. %    Name:    PICTline
  15. %    Syntax:    x1 y1 x2 y2 PICTline -
  16. %    About:    Draws a line from first to second point, using current pattern,
  17. %            width&height. This is drawn in the Mac way, with the pen down
  18. %            and right of coordinate.  pen size of 1 is stroked so it looks
  19. %            better (but not placed as accurately)
  20. %%%%%%%%%%%%%
  21. /PICTline
  22. {
  23.     /endY exch def
  24.     /endX exch def
  25.     /startY exch def
  26.     /startX exch def
  27.  
  28.     %
  29.     %    Only draw if pensize > 0
  30.     %
  31.     penHeight 0 gt
  32.     penWidth 0 gt
  33.     and
  34.     {
  35.         gsave
  36.             penPattern usePattern
  37.             newpath
  38.                 %
  39.                 %    If pensize is 1, do simple display.
  40.                 %
  41.                 penHeight 1 eq
  42.                 penWidth 1 eq
  43.                 and
  44.                 {
  45.                     startX startY moveto
  46.                     endX endY lineto
  47.                     stroke
  48.                 }
  49.                 {
  50.                     %
  51.                     %    Draw the line as a multi-sided shape. compute corner
  52.                     %    coords based on which direction it is drawn in.
  53.                     %
  54.                     endY startY lt
  55.                     {
  56.                         endX startX gt
  57.                         {
  58.                             startX startY moveto
  59.                             endX endY lineto
  60.                             endX penWidth add  endY lineto
  61.                             endX penWidth add  endY penHeight add lineto
  62.                             startX penWidth add  startY penHeight add lineto
  63.                             startX  startY penHeight add lineto
  64.                         }
  65.                         {
  66.                             startX penWidth add startY moveto
  67.                             endX penWidth add endY lineto
  68.                             endX endY lineto
  69.                             endX endY penHeight add lineto
  70.                             startX startY penHeight add lineto
  71.                             startX penWidth add startY penHeight add lineto
  72.                         }
  73.                         ifelse
  74.                     }
  75.                     {
  76.                         endX startX gt
  77.                         {
  78.                             startX startY moveto
  79.                             startX penWidth add startY lineto
  80.                             endX penWidth add endY lineto
  81.                             endX penWidth add endY penHeight add lineto
  82.                             endX endY penHeight add lineto
  83.                             startX startY penHeight add lineto
  84.                         }
  85.                         {
  86.                             startX startY moveto
  87.                             endX endY lineto
  88.                             endX endY penHeight add lineto
  89.                             endX penWidth add endY penHeight add lineto
  90.                             startX penWidth add  startY penHeight add lineto
  91.                             startX penWidth add  startY lineto
  92.                         }
  93.                         ifelse
  94.                     }
  95.                     ifelse
  96.                 closepath
  97.                 fill
  98.             }    % End pensize = 1.
  99.             ifelse
  100.         grestore
  101.     }    % End pensize >0
  102.     if
  103. } def
  104.  
  105.  
  106.  
  107. %%%%%%%%%%%%%
  108. %    Name:    line                [0020]
  109. %    Syntax:    x1 y1 x2 y2 line -
  110. %    About:    Given a pair of x,y coordinates, draw a pict-style line from
  111. %            the first to the last, and store the current point.
  112. %%%%%%%%%%%%%
  113. /line
  114. {
  115.     /endY exch def
  116.     /endX exch def
  117.     /startY exch def
  118.     /startX exch def
  119.  
  120.     startX startY endX endY PICTline    
  121.     
  122.     /currentX endX def
  123.     /currentY endY def
  124. } def
  125.  
  126. %%%%%%%%%%%%%
  127. %    Name:    LineFrom            [0021]
  128. %    Syntax:    x2 y2 line -
  129. %    About:    Draws a line from the current pon to the x and y coord passed.
  130. %%%%%%%%%%%%%
  131. /lineFrom
  132. {
  133.     /endY exch def
  134.     /endX exch def
  135.     currentX currentY endX endY line
  136. } def
  137.  
  138. %%%%%%%%%%%%%
  139. %    Name:    line                [0022]
  140. %    Syntax:    x1 y1 dx dy line -
  141. %    About:    Draws a line from pt 1 to pt 1' (1' = 1 + dx,dy)
  142. %%%%%%%%%%%%%
  143. /shortLine
  144. {
  145.     /dy exch def
  146.     /dx exch def
  147.     /startY exch def
  148.     /startX exch def
  149.     startX  startY startX dx add startY dy add line
  150. } def
  151.  
  152. %%%%%%%%%%%%%
  153. %    Name:    ShortLineFrom        [0023]
  154. %    Syntax:    dx dy ShortLineFrom -
  155. %    About:    Draws a line the current to the pased offset from it
  156. %%%%%%%%%%%%%
  157. /shortLineFrom
  158. {
  159.     /dy exch def
  160.     /dx exch def
  161.     currentX currentY currentX dx add currentY dy add line
  162. } def
  163.  
  164. %END Lines
  165.